package com.jasonzqshen.ifm.wizards;

import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.IWizardContainer;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;

import com.jasonzqshen.ifm.project.FileCreator;

public class NewFeatureModelFile extends Wizard implements INewWizard {
    private NewFeatureModelFilePage page;

    private IStructuredSelection selection;

    public NewFeatureModelFile() {
        this.selection = null;
        this.page = null;
        setNeedsProgressMonitor(true);
    }

    @Override
    public boolean performFinish() {
        final String path = page.getContainerFullPath().toString();
        final String fileName = page.getFileName();
        final Shell shell = getShell();
        IWizardContainer container = getContainer();
        
        FileCreator.createFeatureModelFile(path, fileName, container, shell);
        
        return true;
    }

    @Override
    public void init(IWorkbench workbench, IStructuredSelection selection) {
        this.selection = selection;
    }

    /**
     * Add pages
     */
    @Override
    public void addPages() {
        setWindowTitle("New");
        this.page = new NewFeatureModelFilePage(selection);
        this.addPage(this.page);
    }

}
